package com.gaeainfo.modules.alarm.collection.controller;

import com.gaeainfo.framework.core.basic.dto.BaseResponseDto;
import com.gaeainfo.framework.core.utils.common.GaeaCommonUtil;
import com.gaeainfo.modules.alarm.collection.service.AlarmCollectionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * Created by Caven on 2018/7/13.
 */
@Controller
@RequestMapping("rest/alarm-collection")
public class AlarmCollectionController {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private AlarmCollectionService alarmCollectionService;

    @ResponseBody
    @RequestMapping("get-person-info")
    public BaseResponseDto getPersonInfo(@RequestParam(value = "idCard", required = false) String idCard,
                                         @RequestParam(value = "phone", required = false) String phone) {
        try {
            return BaseResponseDto.successtData(alarmCollectionService.getPersonInfo(idCard, phone));
        } catch (Exception e) {
            logger.error(GaeaCommonUtil.getStackTrace(e));
            return BaseResponseDto.exception(e);
        }

    }


    @ResponseBody
    @RequestMapping(value = "save-alarm-person", method = RequestMethod.POST)
    public BaseResponseDto saveAlarmPerson(@RequestBody String alarmId,
                                           @RequestBody String personId,
                                           @RequestBody String personType) {
        try {
            return BaseResponseDto.successtData(alarmCollectionService.saveAlarmPerson(alarmId, personId, personType));
        } catch (Exception e) {
            logger.error(GaeaCommonUtil.getStackTrace(e));
            return BaseResponseDto.exception(e);
        }

    }

    @ResponseBody
    @RequestMapping("get-alarm-person")
    public BaseResponseDto getAlarmPerson(@RequestParam("alarmId") String alarmId) {
        try {
            return BaseResponseDto.successtData(alarmCollectionService.getAlarmPerson(alarmId));
        } catch (Exception e) {
            logger.error(GaeaCommonUtil.getStackTrace(e));
            return BaseResponseDto.exception(e);
        }

    }

    @ResponseBody
    @RequestMapping(value = "delete-alarm-person", method = RequestMethod.POST)
    public BaseResponseDto deleteAlarmPerson(@RequestBody String alarmId,
                                             @RequestBody String personId) {
        try {
            return BaseResponseDto.successtData(alarmCollectionService.deleteAlarmPerson(alarmId, personId));
        } catch (Exception e) {
            logger.error(GaeaCommonUtil.getStackTrace(e));
            return BaseResponseDto.exception(e);
        }

    }

    @ResponseBody
    @RequestMapping("get-vehicle-info")
    public BaseResponseDto getVehicleInfo(@RequestParam("plateNo") String plateNo) {
        try {
            return BaseResponseDto.successtData(alarmCollectionService.getVehicleInfo(plateNo));
        } catch (Exception e) {
            logger.error(GaeaCommonUtil.getStackTrace(e));
            return BaseResponseDto.exception(e);
        }

    }


    @ResponseBody
    @RequestMapping(value = "save-alarm-vehicle", method = RequestMethod.POST)
    public BaseResponseDto saveAlarmVehicle(@RequestBody String alarmId,
                                        @RequestBody String vehicleId) {
        try {
            return BaseResponseDto.successtData(alarmCollectionService.saveAlarmVehicle(alarmId, vehicleId));
        } catch (Exception e) {
            logger.error(GaeaCommonUtil.getStackTrace(e));
            return BaseResponseDto.exception(e);
        }

    }

    @ResponseBody
    @RequestMapping("get-alarm-vehicle")
    public BaseResponseDto getAlarmVehicle(@RequestParam("alarmId") String alarmId) {
        try {
            return BaseResponseDto.successtData(alarmCollectionService.getAlarmVehicle(alarmId));
        } catch (Exception e) {
            logger.error(GaeaCommonUtil.getStackTrace(e));
            return BaseResponseDto.exception(e);
        }

    }

    @ResponseBody
    @RequestMapping(value = "delete-alarm-vehicle", method = RequestMethod.POST)
    public BaseResponseDto deleteAlarmVehicle(@RequestBody String alarmId,
                                          @RequestBody String vehicleId) {
        try {
            return BaseResponseDto.successtData(alarmCollectionService.deleteAlarmVehicle(alarmId, vehicleId));
        } catch (Exception e) {
            logger.error(GaeaCommonUtil.getStackTrace(e));
            return BaseResponseDto.exception(e);
        }

    }


}
